package main

import (
	"fmt"
	"github.com/TimeBye/go-harbor"
	"github.com/TimeBye/go-harbor/pkg/client"
	"github.com/TimeBye/go-harbor/pkg/model"
	"github.com/TimeBye/go-harbor/pkg/project/options"
	rest2 "github.com/TimeBye/go-harbor/pkg/rest"
)

func main() {
	// user:用户名
	// pwd:密码
	// host:harbor地址。或者是域名
	// repo:仓库名称
	// images:镜像名称
	// tag:版本号
	//host := "https://harbor.baocloud.cn/"
	//user := "xo-container"
	//pwd := "CwAc6euXd3B#"

	host := "https://harbor.container.com/"
	user := "admin"
	pwd := "mhxE6rXb{cedt6o"
	//repo := "xo-container"
	//images := "busybox"
	//tag := "1.0"
	//harbor.NewClientSet(host, user, pwd)
	harborClient, err := client.NewForConfig(&rest2.Config{
		APIPath:  host,
		Username: user,
		Password: pwd,
		TLSClientConfig: rest2.TLSClientConfig{
			Insecure: true,
		},
	})
	if err != nil {
		fmt.Println(err)
	}
	project, err := harborClient.V2.Get("xo-container")
	fmt.Println(project)
	result, err := harborClient.V2.Repositories("xo-container").List(&options.RepositoriesListOptions{})
	//result, err := harborClient.V2.Repositories("anan").Get("mysql")
	if err != nil {
		fmt.Println(result)
	}
	//query := options.ProjectsListOptions{}
	//projects, err := harborClient.V2.List(&query)
	//if err != nil {
	//	fmt.Println(err)
	//}
	//fmt.Println(projects)

}

func Harborv2(user, pwd, host, repo, images, tag string) {
	// harbor:2.0
	harborClient, err := harbor.NewClientSet(host, user, pwd)
	if err != nil {
		panic(err)
	}
	query := model.Query{}
	//用户
	fmt.Println(harborClient.User.Get("1"))
	fmt.Println(harborClient.User.List(&query))
	// fmt.Println(harborClient.User.Delete("6"))

	//仓库
	// fmt.Println(harborClient.V2.Repositories("anan").Get("mysql"))
	// fmt.Println(harborClient.V2.Repositories("anan").List(&query))
	// fmt.Println(harborClient.V2.Repositories("anan").Delete("mysql"))

	//项目
	// fmt.Println(harborClient.V2.Get("15"))
	// fmt.Println(harborClient.V2.List(&query))
	// fmt.Println(harborClient.V2.Delete("11"))

	//制品fmt.Println(harborClient.V2.Repositories("anan").Artifacts("mysql").List(&query))
	fmt.Println(harborClient.V2.Repositories("anan").Artifacts("mysql").Get("5.7"))
	// fmt.Println(harborClient.V2.Repositories("anan").Artifacts("busybox").Delete("1.0"))
}
